// createRouter   创建router 实力对象 (new操作)
// createWebHistory  创建history模式的路由对象

import { createRouter, createWebHashHistory } from 'vue-router'

// 主页
const Layout = () => import('@/views/Layout')

// 首页
const Home = () => import('@/views/Home')

// 一级类目
const Category = function () {
  return import('@/views/Category')
}

// 二级类目
const SubCategory = () => import('@/views/Category/sub.vue')

// 测试路由
const Playground = () => import('@/views/Playground')

// 商品详情路由
const Goods = () => import('@/views/Goods')

// 登录首页路由
const Login = () => import('@/views/Login')

// 购物车页面
const Cart = () => import('@/views/Cart')

// 创建路由实例
const router = createRouter({

  // 配置路由规则，写法和之前一样
  routes: [
    {
      path: '/',
      name: 'layout',
      component: Layout,
      children: [
        {
          path: '',
          name: 'home',
          component: Home
        },
        {
          path: 'category/:id',
          name: 'category',
          component: Category
        },
        {
          path: '/category/sub/:id',
          name: 'subCategory',
          component: SubCategory
        },
        {
          path: 'product/:id',
          name: 'goods',
          component: Goods
        },
        {
          path: '/cart',
          name: 'cart',
          component: Cart
        }
      ]
    },
    {
      path: '/play',
      component: Playground
    },
    {
      path: '/login',
      component: Login
    }

  ],
  // 使用hash方式实现路由
  history: createWebHashHistory()
})

export default router
